package com.jxm.hutools;

import cn.hutool.core.convert.Convert;
import org.junit.Test;

import java.util.Date;
import java.util.List;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2023-12-18 14:07
 * @Version: 1.0
 */
public class ConvertTest {

   // 转换为字符串
    @Test
    public void test1(){
        int a = 1;
        //aStr为"1"
        String aStr = Convert.toStr(a);
        System.out.println(aStr);
        long[] b = {1,2,3,4,5};
        //bStr为："[1, 2, 3, 4, 5]"
        String bStr = Convert.toStr(b);
        System.out.println(bStr);
    }

    //转换为指定类型数组
    @Test
    public void test2(){
        String[] b = { "1", "2", "3", "4" };
        //结果为Integer数组
        Integer[] intArray = Convert.toIntArray(b);
        System.out.println(intArray);
        long[] c = {1,2,3,4,5};
        //结果为Integer数组
        Integer[] intArray2 = Convert.toIntArray(c);
        System.out.println(intArray2);
    }

    //转换为日期对象：
    @Test
    public void test3(){
        String a = "2017-05-06";
        Date value = Convert.toDate(a);
        System.out.println(value);
    }

    //转换为集合
    @Test
    public void test4(){
        Object[] a = {"a", "你", "好", "", 1};
        List<String> convert = Convert.convert(List.class, a);
        List<?> objects = Convert.toList(a);
    }

}
